package com.zp.service;

import java.util.ArrayList;
import java.util.List;

public interface NewSubject {
 
    List<Observer> list = new ArrayList<>();
 
    default void registerObserver(Observer o) {
        list.add(o);
    }
 
    default void nofityAllObserver(String orderNo) {
        list.forEach(c -> c.notify(orderNo));
    }
}
 class Test{
     public static void main(String[] args) {
         NewSubject newSubject = new NewSubject() {
         };

         newSubject.registerObserver((String orderNo)->{
             System.out.println("订单 " + orderNo + " 状态更新为【已支付】");
         });
         newSubject.nofityAllObserver("002");
     }
}